package com.hermit.qmst.UI.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hermit.qmst.R;
import com.hermit.qmst.UI.clickinterface.NoDoubleClickListener;
import com.hermit.qmst.tools.Common;
import com.hermit.qmst.tools.SipCallHelp;

/**
 * Created by hermithermit on 15/5/4.
 */
public class SelectCallActivity extends Activity implements View.OnClickListener{


    private TextView mbtCallFree;
    private TextView mbtCallNor;
    private Button mbtnCancel;
    private TextView mtvDisplayName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_call_select);

        mbtCallFree = (TextView)findViewById(R.id.bt_call_1);
        mbtCallNor = (TextView)findViewById(R.id.bt_call_2);
        mbtnCancel = (Button)findViewById(R.id.bt_cancel);

        mbtCallNor.setOnClickListener(this);
        mbtnCancel.setOnClickListener(this);
        mtvDisplayName = (TextView)findViewById(R.id.tv_diaplay_name);

        if (Common.mCallName != null && Common.mCallName.length() > 0){
            mtvDisplayName.setText(Common.mCallName);
        }else {
            mtvDisplayName.setText(Common.mCallPhone);
        }


        mbtCallFree.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                SipCallHelp.placeCallWithOption(null, SelectCallActivity.this, Common.mCallPhone);
            }
        });
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        finish();

        return true;
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.bt_call_1:
                SipCallHelp.placeCallWithOption(null, this, Common.mCallPhone);
                break;

            case R.id.bt_call_2:
                Intent intent =  new Intent(SelectCallActivity.this,CallingActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.fling_in_right2left, R.anim.fling_out_left2right);
                finish();
//                Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Common.mCallPhone));
//                startActivity(callIntent);
//                finish();
                break;
            case R.id.bt_cancel:
                finish();
                break;
        }

    }
}
